angular.module('starter.controllers')
.controller('InfoCtrl', function($scope, museumFac, $stateParams, $location, $cookies) {
  	$scope.change_language = function(id){
      $scope.language = id;
      var expireDate = new Date();  
      expireDate.setDate(expireDate.getDate() + 30);                
      $cookies.put('language', id, {'expires': expireDate.toUTCString()});
      location.reload();
      if(id == 0){
        document.getElementById('title').innerHTML = '提示';
        document.getElementById('windowclosebutton').value = '确定';
      }else{
        document.getElementById('title').innerHTML = 'Hint';
        document.getElementById('windowclosebutton').value = 'Confirm';
      }

    }

  	$scope.getLanguage = function(){
      $scope.language = $cookies.get('language');
      if($scope.language){
          $scope.language = $scope.language;
      }else{
          $scope.language = 0;
      }
      if($scope.language == 0){
        document.getElementById('title').innerHTML = '提示';
        document.getElementById('windowclosebutton').value = '确定';
      }else{
        document.getElementById('title').innerHTML = 'Hint';
        document.getElementById('windowclosebutton').value = 'Confirm';
      }
    }
    $scope.getLanguage();

    $scope.getUser = function() {
      museumFac.user.profile(function(data){
        $scope.user = data.info;
      },function(data){
        alert(data.data.info);
      });
    };
    $scope.getUser();

    $scope.edit = function(flag){
      $scope.guide = 1;
      $scope.editmark = flag;
    }

    $scope.canclesave = function(){
      $scope.guide = 0;
    }

    $scope.save1 = function(){
      $scope.user.name = $scope.user.name1;
      museumFac.user.editprofile($scope.user,function(data){
        $scope.guide = 0;
        $scope.getUser();
      },function(data){
        alert(data.data.info);
      });
    }

    $scope.save2 = function(flag){
      $scope.user.sex = flag;
      museumFac.user.editprofile($scope.user,function(data){
        $scope.guide = 0;
        $scope.getUser();
      },function(data){
        alert(data.data.info);
      });
    }

    $scope.save3 = function(){
      $scope.birthday = Date.parse(new Date($scope.user.birthday1));
      $scope.user.birthday = $scope.birthday/1000;
      museumFac.user.editprofile($scope.user,function(data){
        $scope.guide = 0;
        $scope.getUser();
      },function(data){
        alert(data.data.info);
      });
    }

    $scope.logout = function(){
      museumFac.user.logout(function(data){
        alert('退出成功');
        $location.url('home');
      },function(data){
        alert(data.data.info);
      });
    }

    $scope.gotoVip = function(){
      window.location.href = 'http://store.sifangartmuseum.org.cn/Home/Index/vip';
    }
})